package logic

import (
	"context"
	"rpc/model/mysql"

	"rpc/goods"
	"rpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsShowLogic {
	return &GoodsShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsShowLogic) GoodsShow(in *goods.GoodsShowRequest) (*goods.GoodsShowResponse, error) {
	// todo: 商品详情

	g := mysql.GoodsZye{}

	err := g.GoodsShow(int(in.GoodsId))
	if err != nil {
		logx.Error("商品详情查询失败", err)
		return nil, err
	}

	return &goods.GoodsShowResponse{
		GoodsTitle:  g.GoodsTitle,
		GoodsPrice:  float32(g.GoodsPrice),
		GoodsStock:  int64(g.GoodsStock),
		GoodsStatus: int64(g.GoodsStatus),
		GoodsAvatar: g.GoodsAvatar,
		GoodId:      int64(g.ID),
	}, nil
}
